package com.breakfast.fun.adapter.user;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.breakfast.fun.R;
import com.breakfast.fun.base.BaseListAdapter;
import com.breakfast.fun.data.entity.user.address.BuildingData;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/1/17.
 */

public class ChooseLocationAdapter extends BaseListAdapter<BuildingData> {


    private chooseLocation mChooseLocation;

    public ChooseLocationAdapter(Context context, List<BuildingData> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_choose_building, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        BuildingData data = getItem(position);

        holder.mTvItemChooseBuildingName.setText(data.getBuilderName());


        holder.mRlItemChooseBuilding.setOnClickListener(v -> {
            mChooseLocation.choose(data.getBuilderName());
//                    EventBus.getDefault().post(new FinishEvent("ChooseBuildingActivity"));

        });
        /*holder.mLlItemChooseArea.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new FinishEvent("ChooseBuildingActivity"));
                EventBus.getDefault().post(data);
            }
        });*/

        return convertView;
    }

    //选择大楼的回调接口
    public interface chooseLocation {
        void choose(String buildName);
    }

    public void setChooseLocation(chooseLocation chooseLocation) {
        mChooseLocation = chooseLocation;
    }


    static class ViewHolder {
        @Bind(R.id.tv_item_choose_building_name)
        TextView mTvItemChooseBuildingName;
        @Bind(R.id.rl_item_choose_building)
        RelativeLayout mRlItemChooseBuilding;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
